<?php
if(isset($_SESSION['QuyenHan']))
{
	
	$vanbandi = new vanbandibs();
	
	if(isset($_POST['btnTim']))
	{
		
		$SovaKyHieu = $_POST['SovaKyHieu'];
		$NoiBanHanh = $_POST['NoiBanHanh'];
		$NgayBanHanh = str_replace('-',',',$_POST['NgayBanHanh']);
		$NgayHetHan = $_POST['TrichYeu'];
		
		
		$vanbandi->SovaKyHieu = $SovaKyHieu;
		$vanbandi->NgayBanHanh = $NgayBanHanh;
		$vanbandi->TrichYeu = $TrichYeu;
		$vanbandi->NoiBanHanh = $NoiBanHanh;
	
	}
	$vanbandi->MaNguoiDangKy = $_SESSION['MaNguoiDung'];
	$dsvb = $vanbandi->getVanBanDenNguoiDangKy();
	$tongsodong =  count($dsvb);
	if(!isset($_GET['start']))
		$start = 0;
	else
		$start = $_GET['start'];
	
	$limit = 15;
	$next = $start + $limit;
	$back = $start - $limit;
	$danhsach = $vanbandi->pageVanBanDenNguoiDangKy($start, $limit);

	
?>

<div id="NoiDung" class="form">
  <h3  class="text-primary">VĂN BẢN ĐI</h3>
  <div style="position:relative; left:840px; top: 20px;"><a href="vanbandi-them"><span class="glyphicon glyphicon-plus-sign" style="font-size:18px"></span></a><a href="#"  style="margin-left:10px"><span id="clickSearch" class="glyphicon glyphicon-search" style="font-size:18px"></span></a></div>
  <div style="margin-top:20px; display:none" id="search">
    <form  action="vanbandi-danhsach-dangky" method="post" role="form">
      <table class="table borderless">
        <tbody>
          <tr>
            <td><div class="form-group form-custom">
                <label  for="sovakyhieu">Số và ký hiệu:</label>
                <input type="text" class="form-control" placeholder="Số và ký hiệu" name="SovaKyHieu" class="required" />
              </div></td>
            <td><div class="form-group form-custom">
                <label  for="trichyeu">Trích yếu:</label>
                <input type="text" class="form-control" placeholder="Trích yếu" name="TrichYeu" class="required" />
              </div></td>
          </tr>
          <tr>
            <td><div class="form-group form-custom">
                <label  for="noibanhanh">Nơi ban hành:</label>
                <input type="text" class="form-control" placeholder="Nơi ban hành" name="NoiBanHanh" class="required" />
              </div></td>
            <td><div class=" form-group form-custom control-group">
                <label class="control-label">Ngày ban hành</label>
                <div class="controls input-append date form_date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                  <input size="16" type="text" value="" readonly="readonly" name="NgayBanHanh" class="form-control">
                  <span class="add-on"><i class="icon-remove"></i></span> <span class="add-on"><i class="icon-th"></i></span> </div>
              </div></td>
          </tr>
          <tr>
            <td colspan="2"><input type="submit" value="Tìm" class="btn btn-primary btn-primary pull-right" name="btnTim" /></td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
  <script>
	$("#clickSearch").click(function()
	{
		$("#search").toggle("fast");
	})
 </script> 
</div>

<!--Bang van ban den-->

<div style="margin-top:20px;">
<form action="vanbandi" method="post">
  <table class="table table-hover table-bordered table-striped">
    <thead>
      <tr>
        <th style="text-align:center"> STT </th>
        <th  style="text-align:center"> Số và ký hiệu </th>
        <th style="text-align:center"> Ngày ban hành </th>
        <th  style="text-align:center"> Trích yếu </th>
        <th style="text-align:center"> Nơi ban hành</th>
     
      </tr>
    </thead>
    <tbody>
      <?php
		
	if(!is_null($danhsach[0]['MaVanBanDi']))
	{
		
				for($i = 0; $i < count($danhsach); $i++)
				{
					$stt=$i+1;
					
					
					if($danhsach[$i]['MaTrangThai'] == 6)
					echo "<tr class='info'>";
					elseif($danhsach[$i]['MaTrangThai'] == 5)
					echo "<tr class='success'>";
						
						echo "<td>".$stt."</td>";
						
						if(isset($_POST['SovaKyHieu']))
							echo "<td> <a href='vanbandi-chitiet_{$danhsach[$i]['MaVanBanDi']}'>".highlight($danhsach[$i]['SovaKyHieu'], $SovaKyHieu)."</a></td>";
						else
							echo "<td> <a href='vanbandi-chitiet_{$danhsach[$i]['MaVanBanDi']}'>{$danhsach[$i]['SovaKyHieu']} </a></td>";
						
					
						
					
						if(isset($_POST['NgayBanHanh']))
							echo "<td>".highlight(InNgay($danhsach[$i]['NgayBanHanh']), str_replace(',','/',$NgayBanHanh) )."</td>";
						else
							echo "<td>".InNgay($danhsach[$i]['NgayBanHanh'])."</td>";
						
						if(isset($_POST['TrichYeu']))
							echo "<td>".highlight($danhsach[$i]['TrichYeu'],$TrichYeu)."</td>";
						else
							echo "<td>{$danhsach[$i]['TrichYeu']}</td>";
						
						if(isset($_POST['NoiBanHanh']))
							echo "<td>".highlight($danhsach[$i]['NoiBanHanh'],$NoiBanHanh)."</td>";
						else
							echo "<td>{$danhsach[$i]['NoiBanHanh']}</td>";
					
						
					echo "</tr>";
				}
	}
	
			?>
    </tbody>
  </table>
  </div>
</form>
<?php
		if($tongsodong > $limit)
		{
			echo "<div id='PhanTrang' align = 'center'>";
				echo "<ul class='pagination pagination-sm'>";
				
					if($start > 0)
						echo "<li><a href='vanbandi-danhsach-dangky_$back'>&laquo;</a></li>";
					$j = 1;
					for($i = 0; $i < $tongsodong; $i += $limit)
					{	   
							echo "<li><a href='vanbandi-danhsach-dangky_$i'>" . $j . "</a></li>";
						$j++;
					}
					if($start + $limit < $tongsodong)
						echo "<li><a href='vanbandi-danhsach-dangky_$next'>&raquo;</a></li>";
				
				echo "</ul>";
			echo "</div>";
			echo "<br/>";
		}
}else
{
	ThongBaoLoi("Vui lòng đăng nhập !");
}
?>
</div>
<script type="text/javascript">
   
	$('.form_date').datetimepicker({
      	format: 'dd-mm-yyyy',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0
    });
	
</script> 
